from datetime import datetime
from sqlalchemy import func as sqlfunc, MetaData, Table, Column, \
        Integer, String, Unicode, DateTime
from sqlalchemy.ext.assignmapper import assign_mapper
from pylons.database import session_context as ctx

meta = MetaData()

options_table = Table('options', meta,
        Column('name', String(64), primary_key=True),
        Column('value', String, nullable=False),
        )

class Option(object):
    def __repr__(self):
        return '<Option %s>' % self.name

option_mapper = assign_mapper(ctx, Option, options_table)

def add_option(name, value):
    Option(name=name, value=value).flush()

def get_option(name):
    return Option.get(name).value

PS_PUBLISH, PS_DRAFT, PS_PRIVATE, 

posts_table = Table('posts', meta,
        Column('id', Integer, primary_key=True, autoincrement=True),
        Column('title', Unicode, nullable=False, default='no title'),
        Column('content', Unicode, nullable=False, default=''),
        Column('created', DateTime, nullable=False, default=datetime.now),
        )

class Post(object):
    def __repr__(self):
        return "<Post %s>" % self.title

post_mapper = assign_mapper(ctx, Post, posts_table)
